IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fncGetGrossProfit]') 
											AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[fncGetGrossProfit]

GO


CREATE Function [dbo].[fncGetGrossProfit]
(
    @Accept numeric(11),
    @Order numeric(11)
)
RETURNS numeric(11,2)
AS
BEGIN
	RETURN (
SELECT CASE
WHEN ISNULL(@Accept, 0)= 0 THEN 0 ELSE 
		  (ISNULL(@Accept, 0)-ISNULL(@Order, 0))
	    / ISNULL(@Accept, 0) END AS GrossProfit)
END

